﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TecBaseObjects.Models.BusinessCases;
using TecBaseObjects.Objects;
using TpGlobalForms.Forms;
using TpOffice.Controller.BusinessCase;
using TpOffice.Interfaces;

namespace TpOffice.Forms.BusinessCase {

    public partial class BusinessCaseMainForm : Form, ITecForm {

        #region Members
        
        BusinessCaseMainController controller;
        string myTitel = "Geschäftsfall: ";

        #endregion

        #region Constructor

        public BusinessCaseMainForm(int businessCaseID) {
            
            InitializeComponent();
            this.controller = new BusinessCaseMainController(this);
            SetFormEventHandler();
            this.controller.LoadModels(businessCaseID);
            SetFormDataSources();
            this.controller.SetFormTitle(myTitel + " " + MyModel.ShortName);
            this.controller.SetFormStatusLabelText();
            
        }

        #endregion

        #region Properties

        public BusinessCaseModel MyModel {
            get;
            set;
        }

        public List<PlzOrt> MyPlzOrtModel {
            get;
            set;
        }

        public List<OrganisationsShortListObj> MyPurchaserModel {
            get;
            set;
        }

        public List<OrganisationsShortListObj> MyInvoiceRecipientModel {
            get;
            set;
        }

        public List<TecUserObj> MyFirstContactUserModel {
            get;
            set;
        }

        public List<TecUserObj> MyCalculationUserModel {
            get;
            set;
        }

        public List<TecUserObj> MySalesUserModel {
            get;
            set;
        }

        public List<TecUserObj> MyFileUserModel {
            get;
            set;
        }

        public List<BusinessCaseStatusObj> MyBusinessCaseStatusModel {
            get;
            set;
        }

        public List<CustomerSourceObj> MyCustomerSourceModel {
            get;
            set;
        }

        #endregion

        #region Methods

        private void SaveMyModel(object sender, EventArgs e) {
            this.controller.Save(this.MyModel);
        }

        private void SetFormEventHandler() {
            this.llKalkulation.Click += new EventHandler(this.controller.CheckKalkulationLink);
            this.btnSpeichern.Click += new EventHandler(SaveMyModel);
            this.FormClosing += new FormClosingEventHandler(this.controller.BeforeCloseMyForm);
            this.btnNewOrganisation.Click += new EventHandler(this.controller.CreateNewOrganisation);

            //this.purchaserComboBox.MouseDoubleClick += new MouseEventHandler(this.controller.OpenOrganisation);
            //this.invoiceRecipientComboBox.MouseDoubleClick += new MouseEventHandler(this.controller.OpenOrganisation);
        }

        public void SetFormDataSources() {
            this.bsBusinessCase.DataSource = this.MyModel;
            this.bsPlzOrt.DataSource = this.MyPlzOrtModel;
            this.bsPurchaser.DataSource = this.MyPurchaserModel;
            this.bsInvoicer.DataSource = this.MyInvoiceRecipientModel;
            this.bsFirstContactUser.DataSource = this.MyFirstContactUserModel;
            this.bsCalculationUser.DataSource = this.MyCalculationUserModel;
            this.bsSalesUser.DataSource = this.MySalesUserModel;
            this.bsFileUser.DataSource = this.MyFileUserModel;
            this.bsBusinessCaseStatus.DataSource = this.MyBusinessCaseStatusModel;
            this.bsCustomerSource.DataSource = this.MyCustomerSourceModel;
        }

        public void SetFormStatusLabelText(string txt) {
            this.toolStripStatusLabel1.Text = txt;
        }
        
        #endregion
        
    }
}
